const url = 'https://movie.douban.com/explore#!type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=0';
const puppeteer = require('puppeteer');
const sleep = time => new Promise(resolve => {
    setTimeout(resolve, time)
}).catch(err => {
    console.log(err);
});
;(async () =>{
    console.log('start visit target page');
    const browser = await puppeteer.launch({
        args: ['--no-sandbox'],
        dumpio: false,
    });
    const page = await browser.newPage();
    await page.goto(url, {
        waitUntil: 'networkidle2'
    });
    await sleep(3000);
    await page.waitForSelector('.more');
    for(let i = 0; i < 1; i++){
        await sleep(3000);
        await page.click('.more');
    }
    const result = page.evaluate(() => {
        var $ = window.$;
        var items = $('.list-wp a');
        var links = [];
        if (item.length >= 1) {
            items.each((index, item) => {
                var it = $(item);
                var doubanId = it.find('div').data('id');
                var title = it.find('.title').text();
                var rate = Number(it.find('.rate').text());
                var poster = it.find('img').attr('src').replace('s_ratio', 'l_ratio');
                links.push({
                    doubanId,
                    title,
                    rate,
                    poster,
                });
            })
        }
        return links;
    });
    browser.close();
    process.send({result});
    process.exit(0);
})();